// Appendix2.7

log using Appendix2.7.log, replace

use "C:\Users\sbstjp\OneDrive - Cardiff University\CES24_Common.dta" // Schaffner, Brian; Shih, Marissa; Ansolabehere, Stephen; Pope, Jeremy, 2025, "Cooperative Election Study Common Content, 2024", https://doi.org/10.7910/DVN/X11EP6, Harvard Dataverse, V3. Accessed on 12 April 2025.

// Social Justice scale
rename CC24_321e defund
rename CC24_444a gendertransition
rename CC24_444b parentalconsentpronouns 
rename CC24_445a raceuniadmissions

*Reverse coding so social justice values are high
foreach var in defund {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' + 1 - `var'
}

* Replace missing values with 0 for the specified variables - this is necessary as Stata doesn't add up missing values and means a 0-1 standardization scale isn't feasible as missing values would overlap with the scale
foreach var in rdefund parentalconsentpronouns gendertransition raceuniadmissions {
    replace `var' = 0 if missing(`var')
}

* Initialize the total score and the count of non-zero responses
gen total_scoreSJV = 0
gen count_nonzeroSJV = 0

* Add each variable to the total scale score and count it if non-zero
foreach var in rdefund parentalconsentpronouns gendertransition raceuniadmissions  {
    replace total_scoreSJV = total_scoreSJV + `var'
    replace count_nonzeroSJV = count_nonzeroSJV + (`var' != 0)
}

* Calculate the average score, avoiding division by zero
gen SocJusValues = .
replace SocJusValues = total_scoreSJV / count_nonzeroSJV if count_nonzeroSJV > 0

// Demographics
*Delete missing values and rename
replace gender4=. if gender4>2
rename gender4 FemaleGender

replace faminc_new=. if faminc_new==97 

generate age = 2024 - birthyr

replace CC24_330a=. if CC24_330a==8 
rename CC24_330a libconsp

*Create dummies
gen Graduate=.
replace Graduate=0 if inrange(educ, 1, 4)
replace Graduate=1 if inlist(educ, 5, 6)

gen BIPOC=.
replace BIPOC=0 if race==1
replace BIPOC=1 if inrange(race, 2, 8)

gen SocCulEmployment=.
replace SocCulEmployment=1 if inlist(industry, 7, 8)
replace SocCulEmployment=0 if inrange(industry, 1, 6)
replace SocCulEmployment=0 if inrange(industry, 9, 17)

// Standardize
egen Age = std(age)
egen Income = std(faminc_new)

// Regressions
regress SocJusValues Age BIPOC FemaleGender Graduate Income SocCulEmployment [pweight=commonweight], robust
eststo
regress SocJusValues Age BIPOC FemaleGender Graduate Income SocCulEmployment if libconsp<4 [pweight=commonweight], robust
eststo
esttab

log close

eststo clear
esttab using "Appendix2.7.rtf", ///
    b(3) se(3) ///
    star(* 0.05 ** 0.01 *** 0.001) ///
    coeflabels(_cons "Constant") ///
    nonumbers replace

// Alternative specification

ologit SocJusValues Age FemaleGender Graduate Income BIPOC SocCulEmployment [pweight=commonweight], robust

